package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Visit;
import com.aaa.tmr.service.VisitService;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * (Visit)表控制层
 *
 * @author makejava
 * @since 2021-03-24 09:47:53
 */
@Controller
@RequestMapping("visit")
public class VisitController {
    /**
     * 服务对象
     */
    @Resource
    private VisitService visitService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @RequestMapping("selectOne")
    public Visit selectOne(Integer id) {
        return this.visitService.queryById(id);
    }

    /**
     * 跳转部门分页列表页面
     *
     * @return
     */
    @RequestMapping("toVisit")
    public String toPage() {
        return "back/visit-page";
    }

    /**
     * 跳转到回访图表分析页面
     * @return
     */

    @RequestMapping("toVisitEchart")
    public String toPageEchart() {
        return "back/visitEchart";
    }
    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param visit
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, Visit visit) {
        PageInfo pageInfo = visitService.queryAll(page, limit, visit);
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }


    /**
     * 部门添加
     *
     * @param visit
     * @return
     */
    @ResponseBody
    @PostMapping("insert")
    public Result insert(Visit visit) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, visitService.insert(visit));
    }

    /**
     * 部门更新
     *
     * @param visit
     * @return
     */
    @ResponseBody
    @PutMapping("update")
    public Result update(Visit visit) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, visitService.update(visit));
    }

    /**
     * 通过主键删除数据
     *
     * @param visitId 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteById")
    public Result deleteById(Integer visitId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.visitService.deleteById(visitId));
    }


    /**
     * 通过主键删除数据
     *
     * @param visitIds 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteByIds")
    public Result deleteByIds(String visitIds) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.visitService.batchDeleteById(visitIds));
    }
    @ResponseBody
    @RequestMapping("importVisit")
    public Result importCustom(@RequestParam MultipartFile file) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                0,visitService.importVisit(file));
    }
    /**
     * 按年月查询图标显示数据
     * @param year
     * @param month
     * @return
     */
    @ResponseBody
    @RequestMapping("queryShowChartData")
    public Result queryShowChartData(Integer year, Integer month) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.visitService.queryShowChartData(year,month));
    }


}
